package com.jdz.gxq.info.admin.envinfo.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import com.jdz.gxq.info.admin.envinfo.bo.Envinfo;
import com.jdz.gxq.info.admin.envinfo.form.EditEnvinfoForm;
import com.jdz.gxq.info.admin.envinfo.service.EnvinfoService;
import com.jdz.gxq.info.common.action.CommonAction;

public class SaveEnvinfoAction extends CommonAction {

	private EnvinfoService envinfoService = null;
	 
	public ActionForward doExecute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws java.lang.Exception {
		
		EditEnvinfoForm editEnvinfoForm = (EditEnvinfoForm) form;
		
		Envinfo envinfo = editEnvinfoForm.getEnvinfo();
		
		// envinfo名重复验证(其他后台逻辑验证也类似处理)
		if (!envinfoService.checkEnvinfoName(envinfo, 2)) {
			ActionMessages messages = new ActionMessages();
			messages.add("envinfo.enterpriseName", new ActionMessage("error.envinfoNameExisted"));
			addErrors(request, messages);
			return mapping.getInputForward();
		}
		
		envinfo.setModifiedBy(getUserId(request));
		
		envinfoService.updateEnvinfo(envinfo);
		
		return mapping.findForward("success");
	}

	public void setEnvinfoService(EnvinfoService envinfoService) {
		this.envinfoService = envinfoService;
	}
}

